package com.cyandpos.pad.activity;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;

import com.cyandpos.pad.cateringformat.CateringMainActivity;
import com.cyandpos.pad.cateringformat.choosemenu.MenuFoodActivity;
import com.cyandpos.pad.common.commondata.Constant;

import java.lang.ref.WeakReference;

/**
 * Created by xin on 2021/9/6
 * desc:
 */
public class MyHandler extends Handler {
    private final WeakReference<Activity> mActivity;
    public MyHandler(Activity activity) {
        this.mActivity = new WeakReference<Activity>(activity);
    }
    @Override
    public void handleMessage(Message msg) {

        switch (msg.what) {
            case Constant.MAIN_UPDATE_CURRENT_TIME_HANDLEID: {
                MainActivity mainActivity = (MainActivity) mActivity.get();
                if (mainActivity == null) {
                    return;
                }
                String time = msg.getData().getString("time");
                mainActivity.tvMainTitleCurrentTime.setText(time);
            }
            break;
            case Constant.CATERING_MAIN_UPDATE_CURRENT_TIME_HANDLEID:{
                if(mActivity.get() instanceof CateringMainActivity) {
                    CateringMainActivity cateringMainActivity = (CateringMainActivity) mActivity.get();
                    if (cateringMainActivity == null) {
                        return;
                    }
                    String time = msg.getData().getString("time");
                    cateringMainActivity.tvCateringMainTitleCurrentTime.setText(time);
                }else if(mActivity.get() instanceof MenuFoodActivity){
                    MenuFoodActivity menuFoodActivity = (MenuFoodActivity) mActivity.get();
                    if (menuFoodActivity == null) {
                        return;
                    }
                    String time = msg.getData().getString("time");
                    menuFoodActivity.tvCateringMainTitleCurrentTime.setText(time);
                }
            }
            break;
            default:
                break;
        }
    }

}
